package novoRIP.servidor;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author yuripadua
 */
public class clienteTCP extends Thread {

    private Socket clientSocket;
    private String clientMessage;

    public clienteTCP(String hostName, int port, String message) throws UnknownHostException, IOException {
        clientSocket = new Socket(hostName, port);
        //Socket clientSocket = new Socket("localhost", 6789);
        clientMessage = message;
    }

    public void run() {
        String modifiedSentence = "";

        try {


            ObjectOutputStream outToServer = new ObjectOutputStream(clientSocket.getOutputStream());
            ObjectInputStream inFromServer = new ObjectInputStream(clientSocket.getInputStream());

            teste objTeste = new teste();
            outToServer.writeObject(objTeste);

            objTeste = (teste) inFromServer.readObject();
            System.out.println("Client: " + objTeste.getAux());
            System.out.println("FROM SERVER: " + modifiedSentence);

            clientSocket.close();

            clientSocket.close();

        } catch (Exception e) {
            Logger.getLogger(serverMulthreadTCP.class.getName()).log(Level.SEVERE, null, e);
        }
    }
}
